package com.mxf.code.product_coupon.config;

import com.mxf.code.product_coupon.service.ProductService;
import com.mxf.code.product_coupon.service.impl.ProductServiceImpl;
import com.mxf.code.product_coupon.strategy.DiscountStrategy;
import com.mxf.code.product_coupon.strategy.FullReductionStrategy;
import com.mxf.code.product_coupon.strategy.PriceCalculator;
import com.mxf.code.product_coupon.strategy.impl.FullReductionForTypeStrategy;
import com.mxf.code.product_coupon.strategy.impl.MemberDiscountStrategy;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置
 *
 * @author 28382
 */
@Configuration
public class AppConfig {
    @Bean(name = "memberDiscountStrategy")
    public DiscountStrategy memberDiscountStrategy() {
        return new MemberDiscountStrategy();
    }

    @Bean(name = "fullReductionForTypeStrategy")
    public FullReductionStrategy fullReductionForTypeStrategy() {
        return new FullReductionForTypeStrategy();
    }

    @Bean(name = "priceCalculator")
    public PriceCalculator priceCalculator(@Qualifier("memberDiscountStrategy") DiscountStrategy discountStrategy,
                                           @Qualifier("fullReductionForTypeStrategy") FullReductionStrategy fullReductionStrategy) {
        return new PriceCalculator(discountStrategy, fullReductionStrategy);
    }

    @Bean(name = "productService")
    public ProductService productService() {
        return new ProductServiceImpl(priceCalculator(memberDiscountStrategy(), fullReductionForTypeStrategy()));
    }
}
